import React, {Component} from 'react';
import {Grid,Search, Button} from '@icedesign/base';
import {
  FormBinderWrapper as IceFormBinderWrapper,
  FormBinder as IceFormBinder,
  FormError as IceFormError,
} from '@icedesign/form-binder';
import './QueryUser.scss';

const {Row, Col} = Grid;
/**
*  用户列表查询
*/
export default class QueryUser extends Component{
   constructor(props) {
     super(props);
     this.state = {
       dataSource: [
         {
           label: "全部",
           value: "",
           filterValue:1,
           disabled: false
         },
         {
           label: "男",
           value: "男",
           filterValue:1,
           disabled: false
         },
         {
           label: "女",
           value: "女",
           disabled: false
         },
         {
           label: "性别未知",
           value: "性别未知",
           disabled: false
         },
         {
           label: "停用",
           value: "停用",
           disabled: false
         },
         {
           label: "启用",
           value: "启用",
           disabled: false
         }
       ],
       value: ""
     };
   }

   //调用查询
   onSearch(obj) {
     let json = {}
     //设置查询参数
     if (obj.key == '男') {
       json['sex'] = 1;
     } else if (obj.key == '女') {
       json['sex'] = 2;
     } else if (obj.key == '性别未知') {
       json['sex'] = 0;
     } else if (obj.key == '停用') {
       json['login_flag'] = 1;
     } else if (obj.key == '启用') {
       json['login_flag'] = 0;
     }else if (obj.key == '全部') {
       json = {};
     } else{
       json['key'] = obj.key;
     }
     this.state.value = obj.key;
     this.setState(this.state);
     this.props.updateQuery(json);
     //调用查询
     this.props.getUserList();
   }

  render(){
    return(
      <div>
        <IceFormBinderWrapper
          value={this.state}
          ref="form">
            <Row wrap={true} gutter={20}>
              <Col span='24'>
                <Search
                  inputWidth={180}
                  value={this.state.value}
                  onSearch={this.onSearch.bind(this)}
                  dataSource={this.state.dataSource}
                  placeholder="搜索"
                  searchText=""
                  name="textName"
                  className="search-style"
                />
              </Col>
            </Row>
        </IceFormBinderWrapper>
      </div>
    )
  }
}
